<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006~2017 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 李邦琦 <1536549251@qq.com>
// +----------------------------------------------------------------------

namespace app\crm\controller;
use think\Loader;
use think\Cache;

class Addcustomer extends CrmController
{
    /**
     * 渲染模板addCustomer
     */
    public function addCustomer()
    {
        $menuname = "Add Customer";
        $p_menuname = $_SESSION['menu'][$menuname]; //父菜单
        $priv = $_SESSION["user_priv"][$p_menuname][$menuname];     
        $this->assign("priv",$priv);

        $result = Loader::model('Department')->recursionDepartment();
        $result = Loader::model('Department')->recursionDepartmentArr($result);
        $this->assign('options', $result);
        // 模板输出
        return $this->fetch('addCustomer');
    }


    /**
     * 添加客户资料
     */
    public function insertCustomer ()
    {
        $data = $_REQUEST;
        $data['create_user'] = $_SESSION['user_info']['username'];
        $data['createtime'] = date('Y-m-d H:i:s');
        $data['dept_id'] = $_SESSION['user_info']['d_id'];
        $yCode = array('A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J');
        $orderSn = $yCode[intval(date('Y')) - 2017] . strtoupper(dechex(date('m'))) . date('d') . substr(time(), -5) . substr(microtime(), 2, 5) . sprintf('%02d', rand(0, 99));
        $num = mt_rand(10000, 99999);
        $data['customer_code'] = $orderSn.$num;
        // print_r($data);exit;
        Loader::model('Addcustomer')->insertCustomer($data);
    }



}